<?php
/**
 * 监听图片状态
 */
class Cli_ListenimgController extends Ctrl_Cli{
    public function indexAction(){
        while(true){
            $tTime = time();
            $tRunlogdir = APPLICATION_PATH . '/shell/runlog/cli_listenimg.run';
            Tool_Fnc::writefile($tRunlogdir,$tTime);
            $this->opt();
            sleep(5);
        }
        exit;
    }
    private function opt(){
        $tPath = realpath(dirname(__DIR__).'/../../').'/public/';//定义初始图片路径
        //echo $tPath;
        $tCHIMO = new Case_Huadao_InfoModel;
        //$tDatas = $tCHIMO->field('ID id,imgurl,created')->where('is_firsttrial=1')->fList();
        $tSql = 'select ID id,imgurl,created from '.$tCHIMO->table.' where is_firsttrial=1';
        $tDatas = $tCHIMO->query($tSql);
        $tPath = $tPath . strstr($tDatas[0]['imgurl'],'upload');//图片路径
        
        foreach($tDatas as $tKey=>$tValue){
            $tTimediff = $this->timediff($tValue['created']);
            //$tTimediff = floor((time() - $tValue['created'])/3600/24);
            
            if($tTimediff > 30){//判断时间差是否超过一个月
                system('rm '.$tPath);
            }    
        }
        Tool_Fnc::ajaxMsg('执行成功',1);
    }
    //求取时间差 单位：天/
    public function timediff($pCreated){
        $starttime = $pCreated;//开始时间
        $endtime = time();//结束时间
        $cle = $endtime - $starttime;
        $d = floor($cle/3600/24);
        return $d;
    }
}
?>
